#include "cosa.h"

SDL_Surface *screen;


void dibujar(SDL_Surface *img, int x, int y)
{
	SDL_Rect dest;
	dest.x = x;
	dest.y = y;
	dest.w = img->w;
	dest.h = img->h;
	
	SDL_Rect dest2;
	dest2.x = 0;
	dest2.y = 0;
	dest2.w = screen->w;
	dest2.h = screen->h;
  
	SDL_BlitSurface(img, &dest, screen, &dest2);
}

int main(int argc, char* argv[])
{
	//image = SDL_DisplayFormat(temp);
	//SDL_FreeSurface(temp);
	
	// Inicializando
	if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO) < 0) cout << ":( error al iniciar SDL: %s\n" << SDL_GetError() << endl;
	
	atexit(SDL_Quit);
	
	screen = SDL_SetVideoMode(800, 600, 16, SDL_HWSURFACE|SDL_DOUBLEBUF);
	if (screen == NULL) cout << "error al setear el modo de video :(  %s\n"<< SDL_GetError() << endl;
	
	SDL_WM_SetCaption("25 ", "XD");
	
	SDL_Surface *back;
	SDL_Surface *image;
	SDL_Surface *temp;

	back = SDL_LoadBMP("bg.bmp");
	
	temp = SDL_LoadBMP("m.bmp");
		if (temp == NULL) {
		printf("Unable to load bitmap: %s\n", SDL_GetError());
		return 1;
	}
	
	image = SDL_DisplayFormat(temp);
	// Terminar de inicializar
	
	SDL_Rect dest, src;
	
	//Construct the source rectangle for our blit
	src.x = 0;
	src.y = 0;
	src.w = image->w;	//Use image->w to display the entire width of the image
	src.h = image->h;	//Use image->h to display the entire height of the image
	
	//Construct the destination rectangle for our blit
	dest.x = 100;		//Display the image at the (X,Y) coordinates (100,100)
	dest.y = 100;
	dest.w = image->w;	//Ensure the destination is large enough for the image's entire width/height
	dest.h = image->h;
	
	//Blit the image to the backbuffer
	SDL_BlitSurface(image, NULL, screen, NULL);
	
	//Flip the backbuffer to the primary
	SDL_Flip(screen);
	
	//Wait for 2500ms (2.5 seconds) so we can see the image
	//SDL_Delay(2500);
	
	SDL_Event ev;
	while(true) {
	
		while(SDL_PollEvent(&ev)) {
			
			if(ev.type == SDL_QUIT)return 0;
			if(ev.type == SDL_KEYDOWN)return 0;
		}
	}
	

	
	return 0;
}

